package com.hss.nestscroll.recyview;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SnapHelper;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hss.recyclerviewtest.MessagesAdapter;
import com.hss.recyclerviewtest.R;
import com.hss.recyclerviewtest.decoration.SpaceDecoration;

import java.util.ArrayList;
import java.util.List;

public class NestScrollRecyActivity extends AppCompatActivity {
    RecyclewNestScrollView         nestedscrollview;
    RecyclerView recyclerview;
    MessagesAdapter messagesAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nest_scroll_recv);
        nestedscrollview = findViewById(R.id.nestedscrollview);
        recyclerview = findViewById(R.id.recyclerview);
        initRecyclerView();
        nestedscrollview.setNestedScrollChild(recyclerview);
    }
    void initRecyclerView() {
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        SnapHelper snapHelper = new LinearSnapHelper();
        snapHelper.attachToRecyclerView(recyclerview);

        SpaceDecoration spaceDecoration = new SpaceDecoration(true,100);
        recyclerview.addItemDecoration(spaceDecoration);
        recyclerview.setHasFixedSize(false);
        if (messagesAdapter == null){
            messagesAdapter = new MessagesAdapter();
        }
        List<String > list = new ArrayList<>();
        for (int i=0;i<50;i++){
            list.add(String .valueOf(i));
        }
        messagesAdapter.addData(list);
        recyclerview.setAdapter(messagesAdapter);
        messagesAdapter.bindToRecyclerView(recyclerview);


        messagesAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_BOTTOM);
//        messagesAdapter.isFirstOnly(false);  //动画默认只执行一次,如果想重复执行可设置
        messagesAdapter.disableLoadMoreIfNotFullPage();//默认第一次加载会进入回调，如果不需要可以配置：

//        messagesAdapter.setEmptyView(R.layout.empty_view);
    }
}
